package bean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "login_user",urlPatterns = "/login_user")
public class login_user extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doLogin(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected  void doLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        String name=request.getParameter("name");
        String passwd=request.getParameter("passwd");
        User user=function.Login_Exit(name,passwd);

        if(user==null) { response.sendRedirect("/error.jsp"); }
        else
        {
            request.getSession().setAttribute("LocalUser",user);
            response.sendRedirect("/interface.jsp");
        }
    }
}
